Passed
Push — master ( 6f8171...7c2bcd )
by
unknown
48s
created

DepartmentAPI.getDepartments   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 1
rs 10
1
/* 
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
7
8
9
var DepartmentAPI = {};
10
DepartmentAPI.departments = [];
11
12
13
//below are the functions for the tabbed layout of the 'create job poster' page for managers
14
DepartmentAPI.loadFromJSON = function(data) {
15
    
16
    console.log(data);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
17
    
18
    DepartmentAPI.departments = data;
19
    
20
    /*for(var department in departments) {
21
        DepartmentAPI.departments.push( department.id );
22
    }*/
23
    
24
    console.log(DepartmentAPI.departments);
25
    
26
    var createEditProfile_department = document.getElementById("createEditProfile_department");
27
    
28
    for(var department in DepartmentAPI.departments){
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
29
        var option = document.createElement("option");
30
        option.setAttribute("value",DepartmentAPI.departments[department].id);
31
        option.innerHTML = DepartmentAPI.departments[department].value;
32
        createEditProfile_department.appendChild(option);
33
    }
34
    
35
};
36
37
DepartmentAPI.filterCreateJobPosterDepartments = function(firstLoad){
38
    var departmentList = document.getElementById("createJobPoster_listOfDepartments");
39
    Utilities.clearSelectOptions(departmentList);
0 ignored issues
show
Bug introduced by
The variable Utilities seems to be never declared. If this is a global, consider adding a /** global: Utilities */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
40
    
41
    //Grab current text
42
    var departmentSearchBox="";
43
    if(firstLoad !== true){
44
        departmentSearchBox = document.getElementById("createJobPoster_department").value;
45
    }
46
    for(var i = 0;i < DepartmentAPI.departments.length;i++){
47
        var departmentData = DepartmentAPI.departments[i];
48
        console.log(departmentData);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
49
        if(DepartmentAPI.departments[i].toLowerCase().includes(departmentSearchBox.toLowerCase())){
50
            var department = document.createElement("li");
51
            var dLink = document.createElement("a");
52
            dLink.innerHTML = DepartmentAPI.departments[i];
53
            dLink.setAttribute("href","javascript:DepartmentAPI.fillField('"+DepartmentAPI.departments[i]+"')");
0 ignored issues
show
Coding Style introduced by
Script urls should not be used.
Loading history...
54
            department.innerHTML = "";
55
            
56
            department.appendChild(dLink);
57
            departmentList.appendChild(department);
58
        }
59
    }
60
};
61
62
/**
63
 * @param {type} element
64
 * @returns {undefined}
65
 */
66
DepartmentAPI.fillField = function(val){
67
    var departmentSearchBox = document.getElementById("createJobPoster_department");
68
    departmentSearchBox.value = val;
69
    
70
};
71
72
73
DepartmentAPI.getDepartments = function(locale){
74
    var departments_url = DataAPI.baseURL+"/"+locale+"/Lookup/department";
0 ignored issues
show
Bug introduced by
The variable DataAPI seems to be never declared. If this is a global, consider adding a /** global: DataAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
75
    DataAPI.sendRequest(departments_url, "GET", {}, null, function(request) {
76
        DepartmentAPI.loadedManagerDepartments(request.response);
77
    });
78
};
79
80
81
DepartmentAPI.loadedManagerDepartments = function(response){
82
    setTimeout(function(){
83
        DepartmentAPI.loadFromJSON(JSON.parse(response));
84
    }
0 ignored issues
show
Bug introduced by
There seems to be a bad line break before ,.
Loading history...
85
    ,1000);
0 ignored issues
show
introduced by
Comma warnings can be turned off with 'laxcomma'.
Loading history...
86
};